package com.example.a06;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.*;

import javax.annotation.PostConstruct;

public class MyBean
        implements BeanNameAware, ApplicationContextAware, InitializingBean {

    private static final Logger log = LoggerFactory.getLogger(MyBean.class);

    @Override
    public void setBeanName(String name) {
        log.debug("当前的bean" + this + "名字叫" + name);
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.debug("当前的bean" + this + "容器是: " + applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.debug("当前的bean" + this + "初始化");
    }

    @Autowired
    public void  aaa(ApplicationContext context){
        log.debug("当前的bean" + this + "使用 @Autowired 容器是: " + context);
    }

    @PostConstruct
    public void init(){
        log.debug("当前的bean" + this + "使用 @PostConstruct 初始化");
    }
}
